package ngames.com.sushitv.base;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.TextView;

import java.util.List;

import ngames.com.sushitv.AppApplication;
import ngames.com.sushitv.R;
import ngames.com.sushitv.core.AppModel;
import ngames.com.sushitv.core.AppModelImpl;
import ngames.com.sushitv.view.DialogAppLoading;

/**
 * Created by Administrator on 2016/1/14.
 */
public class BaseAction {
    protected Activity mActivity;
    protected View mBaseView;
    protected AppApplication mAppApplication;
    protected AppModelImpl mAppModel;
    protected DialogAppLoading mDialogLoading;

    public BaseAction(Activity activity, View baseView){
        mActivity = activity;
        mBaseView = baseView;
    }

    public void onCreate(){
        getAppModel();
    }

    public void onResume(){

    }

    public void onPause(){

    }

    public void onStop(){

    }

    public void onDestroy(){

    }

    public void onActivityResult(int requestCode, int resultCode, Intent data){

    }

    public void onTitleBack(View v) {

    }

    protected View findViewById(int id) {
        return mActivity.findViewById(id);
    }

    protected Drawable getDrawable(int id) {
        return mActivity.getResources().getDrawable(id);
    }

    protected String getString(int resId) {
        return mActivity.getString(resId);
    }

    protected String getString(int resId, Object... formatArgs) {
        return mActivity.getString(resId, formatArgs);
    }

    public void setTitle(int resid){
        ((TextView) findViewById(R.id.txv_title)).setText(resid);
    }

    public void setTitle(String title){
//        ((TextView) findViewById(R.id.txv_title)).setText(title);
    }

    public AppApplication getAppApplication(){
        if (mAppApplication == null) {
            mAppApplication = (AppApplication) mActivity.getApplication();
        }
        return mAppApplication;
    }

    public AppModel getAppModel(){
        if (mAppModel == null || mAppApplication == null) {
            mAppModel = (AppModelImpl) getAppApplication().getAppModel();
        }
        return mAppModel;
    }

    protected void showProgress(boolean show) {
        if (show) {
            if (mDialogLoading == null) {
                mDialogLoading = new DialogAppLoading(mActivity);
            }
            if (!mDialogLoading.isShowing()) {
                mDialogLoading.show();
            }
        } else {
            if (mDialogLoading != null && mDialogLoading.isShowing()) {
                mDialogLoading.cancel();
            }
        }
    }

    public static boolean isEmptyList(List list) {
        if (list == null || list.isEmpty()) {
            return true;
        } else {
            return false;
        }
    }
}
